package org.ushio.nchu_22201406.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ushio.common_module.entity.MyPackage;
import org.ushio.nchu_22201406.service.packageService;

import java.util.List;
import java.util.Map;
@CrossOrigin(origins = "http://localhost:8080")
@RestController
@RequestMapping("/api")
public class packageController {
    private final packageService packageService;

    @Autowired
    public packageController(packageService packageService) {
        this.packageService = packageService;
    }

    @PutMapping("/package")
    public void updatePackageId(@RequestBody Map<String, Object> payload) {
        String phoneNumber = (String) payload.get("phoneNumber");
        int newPackageId = (int) payload.get("Package_ID");
        packageService.updatePackageId(phoneNumber, newPackageId);
    }

    @GetMapping("/packages")
    public List<MyPackage> getAllPackages() {
        return packageService.getAllPackages();
    }

    @PostMapping("/upPackage")
    public void updatePackage(@RequestBody MyPackage myPackage) {
        packageService.updatePackage(myPackage);
    }
}
